package day14;

/**
 * @author oldliu
 * @since 1.0
 */
public class SingleTon {
    private static SingleTon instance;

    private SingleTon() {
        System.out.println("对象构建了");
        try {
            Thread.sleep((long) (100*Math.random()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public static SingleTon get() {
        if (instance == null) {
            ///
            synchronized (SingleTon.class){
                if(instance==null){
                    instance=new SingleTon();
                }
            }
        }
        return instance;
    }
//    public static SingleTon get() {
//        if (instance == null) {
//            instance = new SingleTon();
//        }
//        return instance;
//    }
}
